package com.woniuxy.dr_mall.provider;

import com.woniuxy.dr_mall.entity.DrSpec;
import com.woniuxy.dr_mall.entity.DrSpecEntry;
import com.woniuxy.dr_mall.entity.DrSpecVO;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author 张哲轩
 * @version 1.0.0
 * @ClassName SpecProvider.java
 * @createTime 2021年08月13日 10:56:00
 */
public class SpecProvider {
    public String select(DrSpecVO specVO) {
        return new SQL() {
            {
                SELECT("*");
                FROM("dr_spec_price");
                WHERE("productId=" + specVO.getProductId());
                for (DrSpecEntry specCondition : specVO.getSpecEntries()) {
                    WHERE(specCondition.getName() + "=" + specCondition.getSpecValId());
                }
            }
        }.toString();
    }

    /**
     * @param spec:
     * @param productId:
     * @return java.lang.String
     * @description:
     * @Author 张哲轩
     * @Date 2021/8/16 9:53
     */
    public String selectVal(DrSpec spec, int productId) {
        //select distinct #{column} from dr_spec_price
        return new SQL() {
            {
                SELECT_DISTINCT(spec.getCode());
                FROM("dr_spec_price");
                WHERE("productId=" + productId);
            }
        }.toString();
    }
}
